﻿using UnityEngine;
using System.Collections;

public class EndGame : MonoBehaviour 
{
	private string sceneLink = "Main Menu";
	public bool gameOver = false;
	public AudioClip gameOverMusic;
	public AudioClip victoryMusic;
	public Unit self, enemy;
	bool music=false;
	void Update(){

		if(enemy.isDead () && !music)
		{
			GameObject.Find ("Main Camera").audio.clip = victoryMusic;
			GameObject.Find ("Main Camera").audio.Play ();
			music=true;
		}
		else if(self.isDead ()&&!music)
		{
			GameObject.Find("Main Camera").audio.clip = gameOverMusic;
			GameObject.Find ("Main Camera").audio.Play ();
			music=true;
		}
	}
	void OnGUI()
	{

		if(gameOver || self.isDead() || enemy.isDead())
			if (GUI.Button (new Rect (Screen.width/2 - 50, Screen.height/2, 100, 30), "Main Menu")) 
			{
				Application.LoadLevel (sceneLink);
			}
	}
}
